<?php

use GatewayWorker\Lib\Db;
use GatewayWorker\Lib\Gateway;


class Events
{
    public static function onConnect($client_id)
    {

    }

    public static function onMessage($client_id, $message)
    {
        $message = str_replace(array("\r\n", "\r", "\n"), "", $message);
        $returnmsg = Events::protocol($message);
        try {
            $db1 = Db::instance('db1');
            $insert_id = $db1->insert('jt808log')->cols(
                array('msg' => $message, 'returnmsg' => $returnmsg))->query();

        } catch (\Exception $e) {
            exit(250);
        } catch (\Error $e) {
            exit(250);
        }

        Gateway::sendToClient($client_id, $returnmsg);
        return;
    }

    public static function onClose($client_id)
    {

    }

    public static function protocol($value)
    {

        return $value." --- protocol";
    }



}
